package cn.dengta.webapp.im.entity;

import java.util.Calendar;
import java.util.Date;

import cn.dengta.common.model.Status;
import cn.dengta.common.model.TimeInterval;
import cn.dengta.webapp.base.entity.TimeBasedEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import me.codeplayer.util.EasyDate;
import me.codeplayer.util.X;

/**
 * 女用户速配奖励记录表
 *
 * @author lgy
 * @since 2022-09-06
 */
@Setter
@Getter
@Accessors(chain = true)
@TableName("dt_speed_dating_reward_log")
public class SpeedDatingRewardLog extends TimeBasedEntity {

	/** 用户ID */
	private Long userId;
	/** 速配次数 */
	private Integer datingTimes;
	/** 速配成功次数 */
	private Integer successTimes;
	/** 速配时长（秒） */
	private Long totalDuration;
	/** 速配次数 */
	private Integer durationCount;
	/** 总消耗钻石 */
	private Integer totalCost;
	/** 速配奖励ID */
	private Long speedDatingRewardId;
	/** 开始时间 */
	private Date reportTime;
	/** 状态 */
	private Integer status;

	public SpeedDatingRewardLog init(SpeedDatingRewardLog input, Date now) {
		this.userId = input.userId;
		this.datingTimes = X.expectNotNull(input.datingTimes, 0);
		this.successTimes = X.expectNotNull(input.successTimes, 0);
		this.totalDuration = X.expectNotNull(input.totalDuration, 0L);
		this.durationCount = X.expectNotNull(input.durationCount, 0);
		this.totalCost = X.expectNotNull(input.totalCost, 0);
		this.reportTime = input.reportTime;
		this.status = X.expectNotNull(input.status, 0);
		super.initTime(now);
		return this;
	}

	public boolean settled() {
		return Status.asResult(status);
	}

	/**
	 * 根据基本时间算出时间范围
	 *
	 * @param baseTime 基本时间
	 * @return [weekInterval = 一周时间范围]
	 */
	public static TimeInterval weekInterval(Long baseTime) {
		final EasyDate d = baseTime != null ? new EasyDate(baseTime) : new EasyDate();
		d.addDay(1 - d.getWeekDay()); // 周一
		return new TimeInterval(d.beginOf(Calendar.DAY_OF_MONTH).toDate(), d.addDay(6).endOf(Calendar.DAY_OF_MONTH).toDate(), -1, -1); // 一周时间段范围
	}

	public static final String USER_ID = "user_id";
	public static final String DATING_TIMES = "dating_times";
	public static final String SUCCESS_TIMES = "success_times";
	public static final String TOTAL_DURATION = "total_duration";
	public static final String DURATION_COUNT = "duration_count";
	public static final String TOTAL_COST = "total_cost";
	public static final String SPEED_DATING_REWARD_ID = "speed_dating_reward_id";
	public static final String REPORT_TIME = "report_time";
	public static final String STATUS = "status";

}
